package com.entrogy.timing;

import com.entrogy.bean.*;
import com.entrogy.dao.*;
import com.entrogy.utils.SendUtils;
import com.entrogy.utils.StrUtils;
import com.entrogy.utils.THDio;
import com.entrogy.utils.constants.Constants;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

@Component
public class TimingTaskService {

    private static final Logger logger = LoggerFactory.getLogger(TimingTaskService.class);

    private static TimingTaskService timingTaskService;

    private String[] outTypes = {"000", "001", "010", "011", "100", "101", "110", "111"};
    @Autowired
    private THDio thd;
    @Autowired
    private AttendanceMapper attDao;
    @Autowired
    private PassRecordMapper prDao;
    @Autowired
    private MachineMapper mDao;
    @Autowired
    private MessageMapper messageDao;
    @Autowired
    private SchoolMapper schoolDao;
    @Autowired
    private PayMapper payDao;

    @PostConstruct
    public void init() {
        timingTaskService = this;
        timingTaskService.thd = this.thd;
        timingTaskService.attDao = this.attDao;
        timingTaskService.prDao = this.prDao;
        timingTaskService.mDao = this.mDao;
        timingTaskService.messageDao = this.messageDao;
        timingTaskService.schoolDao = this.schoolDao;
        timingTaskService.payDao = this.payDao;
    }

    private TimeUtils tUtils = new TimeUtils();

    // A.创建动态时间表
    public void createDynTable(String date, String tableArrange, String tableCycle, String teacherId) {
        String curDateTime = tUtils.getCurrentDateTime();
        try {
            if (timingTaskService.attDao.getArrangeInfor(date) == null) {//当天的时间规则映射表 每个学校都一样
                // 如果没有当天的，就插入（当天时间的规则映射表）和新建
                if ((timingTaskService.attDao.addArrangeInfor(date, tableArrange, tableCycle, teacherId, curDateTime)) > 0) {
                    timingTaskService.attDao.createDynArrange(tableArrange); //创建每天的出行时间规则表 加一个学校ID 去区分是哪个学校
                    int curWeekNum = tUtils.getWeekNum(date);
                    int type = 1;  //用来标识的
                    //获取所有学校的ID 对每个学校创建动态时间表
                    List<SchoolEntity> schoolEntities = timingTaskService.schoolDao.getTotalSchoolInformation();
                    for (SchoolEntity schoolEntity : schoolEntities) {
                        if ((timingTaskService.attDao.getStaticArrangeToDyn(tableArrange, curWeekNum, schoolEntity.getSchoolCode())) > 0) {//获取静态时间规则表 每个学校都不同,然后插入到dyn_arrange表中
                            // 新建当天的时间规则  新建时间规则表，某个年级的某种学生就对应某种时间段
                            //注意：每个学校不同哟
                            if (type == 1) {//判断是否创建
                                type = timingTaskService.attDao.createDynCycle(tableCycle);
                            }
                            timingTaskService.attDao.insetDynCycle(tableCycle, schoolEntity.getSchoolCode());
                        } else {
                            // 插入6个数据失败不太可能
                        }
                    }
                } else {
                    // 插入失败
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // B.把当天某个年级的时间更新到cycle表里
    public void updateDynCycle(String tableCycle, ArrangeEntity arrBean) throws SQLException {
        for (String outType : outTypes) {
            String timeSlot = getTimeSlot(arrBean, outType);
            int type = (timeSlot.equals("")) ? 0 : 1;
            timingTaskService.attDao.updateDynCycle(tableCycle, type, timeSlot, arrBean.getCourseId(), outType, arrBean.getSchoolCode());
        }
    }

    // B.1.根据学生出行种类获得时间段
    public String getTimeSlot(ArrangeEntity arrBean, String outType) {
        String afternoon = arrBean.getAfternoon();
        String evening = arrBean.getEvening();
        String night = arrBean.getNight();
        String timeSlot = "";
        int dayId = arrBean.getDayId();
        if (4 == dayId) {
            // 放假日 do nothing
        } else if (3 == dayId) {
            // 这里有些问题，离校时间在evening和night的无法区别，会导致应该在晚上离校的离不了
            if (outType.charAt(0) == '1') {
                timeSlot += ";" + afternoon;
            }
            timeSlot += ";" + evening;
        } else {
            if (outType.charAt(0) == '1') {
                timeSlot += ";" + afternoon;
            }
            if (outType.charAt(1) == '1') {
                timeSlot += ";" + evening;
            }
            if (outType.charAt(2) == '1') {
                timeSlot += ";" + night;
            }
        }
        if (timeSlot.length() > 0)
            timeSlot = timeSlot.substring(1);
        return timeSlot;
    }

    // C.按照某个年级当天的安排更新时间段并且设置权限
    // courseId可以使班级id也可以是年级id
    private void pushTime(String cycleTable, ArrangeEntity dynArrBean, int courseId, int schoolCode) throws SQLException {
        logger.info("当前推送的学校是=======>" + schoolCode);
        int dayId = dynArrBean.getDayId();
        // 获得该年级或者该班级所在年级的8个时间段规则
        List<CycleEntity> cycleLists = timingTaskService.attDao.getCycleList(cycleTable, dynArrBean.getCourseId(), dynArrBean.getSchoolCode());
        for (CycleEntity cycle : cycleLists) {
            // 更新时间规则参数
            String cycleName = cycle.getCycleName();
            String timeSlot = cycle.getTimeslot();//时间段
            int cycleId = cycle.getCycleId();
            // 更新设备时间规则
            submitCycle(cycleName, 3, getCycleValue(timeSlot), cycleId, schoolCode); //3--(7天value值一样)每天 4--自定义
            // 更新权限参数
            int passNumber = timeSlot.split(";").length;
            int type = cycle.getType();
            String outType = cycle.getOutType();
            String deviceIds = getDeviceIds(true, schoolCode, Constants.THDID_AI06); //获取设备每个学校的设备不一致
            String[] personIds = getPersonIds(courseId, outType, dayId, schoolCode);
            String pushIds = personIds[0];
            int pushNum = pushIds.split(",").length;
            String notPushIds = personIds[1];
            int notPushNum = notPushIds.split(",").length;
            // 更新权限
            logger.info("更新权限" + pushNum + cycleName + "pushIds:" + pushIds);
            logger.info("更新权限" + notPushNum + cycleName + "notPushIds:" + notPushIds);
            SchoolThdidUrlEntity schoolThdidUrl = timingTaskService.schoolDao.getSchoolThdidUrlAndGroupInfo(schoolCode, Constants.THDID_AI06);
            if (pushIds.length() > 0 && schoolThdidUrl != null) {
                // 推可以出门的
                logger.info("可以出门的时间权限推送成功");
                if (!StrUtils.isNullOrEmpty(deviceIds)) {
                    new ChangePersonTimeThread(deviceIds, pushIds, type, cycleId, cycleName, passNumber, 111111111L,
                            99999999999L, "每天定时pushIds有" + pushNum + "个", 0, schoolThdidUrl.getPathUrl(),
                            schoolThdidUrl.getAccessToken()).start();
                }
            }
            if (notPushIds.length() > 0 && schoolThdidUrl != null) {
                // 不能出门的也要推
                logger.info("不可以出门的时间权限推送成功");
                if (!StrUtils.isNullOrEmpty(deviceIds)) {
                    new ChangePersonTimeThread(deviceIds, notPushIds, 0, 1, cycleName, passNumber, 111111111L, 99999999999L,
                            "每天定时notPushIds有" + notPushNum + "个", 0, schoolThdidUrl.getPathUrl(), schoolThdidUrl.getAccessToken()).start();
                }
            }
        }
    }

    // C.1.修改时间段的函数
    public void submitCycle(String name, int type, String cycleValue, int cycleId, Integer schoolCode) {
        JSONObject reqSubmitCycle = new JSONObject();
        reqSubmitCycle.put("name", name);
        reqSubmitCycle.put("type", type);
        reqSubmitCycle.put("cycle_value", cycleValue);
        reqSubmitCycle.put("cycle_id", cycleId);
        // System.out.println("/competence/submit_cycle " + reqSubmitCycle.toString());
        logger.info("设置时间段开始 " + reqSubmitCycle.toString());
        SchoolThdidUrlEntity schoolThdidUrl = timingTaskService.schoolDao.getSchoolThdidUrlAndGroupInfo(schoolCode, Constants.THDID_AI06);
        JSONObject resSubmitCycle = timingTaskService.thd.THD_interface(schoolThdidUrl.getPathUrl(), "/competence/submit_cycle", reqSubmitCycle, false, schoolThdidUrl.getAccessToken());
        logger.info("设置时间段结束 " + resSubmitCycle.toString());
        // System.out.println(resSubmitCycle.toString());
    }

    // C.2.封装cycle_value
    public String getCycleValue(String timeSlot) {
        JSONObject cycleValue = new JSONObject();
        String[] weeks = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
        for (String weekday : weeks) {
            cycleValue.put(weekday, timeSlot);
        }
        return cycleValue.toString();
    }

    // C.3.获得设备id
    public String getDeviceIds(boolean isOut, int schoolCode, String deviceModel) {
        MachineEntity machine = new MachineEntity();
        machine.setIsout(isOut ? 1 : null);
        machine.setSchoolCode(schoolCode == 0 ? null : schoolCode);
        machine.setDeviceModel(deviceModel);
        StringBuilder devices = new StringBuilder();
        List<MachineEntity> machineList = timingTaskService.mDao.listMachine(machine);
        for (MachineEntity machineEntity : machineList) {
            String deviceId = machineEntity.getMachineId();
            devices.append(",").append(deviceId);
        }
        if (devices.length() > 0) {
            devices = new StringBuilder(devices.substring(1));
        }
        return devices.toString();
    }

    // C.4.根据班级和stutype获得personnelids,逗号隔开
    private String[] getPersonIds(int courseId, String outType, int dayId, int schoolCode) {
        String[] persons = {"", ""};
        // 需要出去或者不能出去的学生
        StringBuilder pushIds = new StringBuilder();
        // 肯定不能出去的学生，在离校日才会被赋值
        StringBuilder notPushIds = new StringBuilder();
        List<StudentEntity> stuBeanList;
        try {
            stuBeanList = timingTaskService.attDao.getStudentListByCourseIdAndOutType(Integer.parseInt(String.valueOf(courseId).substring(0, 3)), outType, schoolCode);
            for (StudentEntity stuBean : stuBeanList) {
                if (stuBean.getStudentThdid() == 0) {
                    continue;
                }
                int stuId = stuBean.getId();
                String thdId = stuBean.getStudentThdid() + "";
                List<StudentEntity> leaveList = timingTaskService.attDao.needPushTime(stuId, System.currentTimeMillis() / 1000);
                if (leaveList.size() > 0) {
                    // 当前时间该学生有请假正在生效，不推送时间，等请假的定时任务推送
                    logger.info(stuBean.getStudentName() + "有请假，不推时间");
                    continue;
                }
                // 有些傻屌学生一定要家长来接，所以当天是离校日的不能放他们出去
                if (3 == dayId) {
                    if (stuBean.getLeaveType() == 1) {
                        // 自由出行的学生
                        if (thdId != null && !thdId.equals("")) {
                            pushIds.append(",").append(stuBean.getStudentThdid());
                        }
                    } else {
                        // 不是自由出行的学生包括（家长接的，校车的，周末托管的）
                        if (thdId != null && !thdId.equals("")) {
                            notPushIds.append(",").append(stuBean.getStudentThdid());
                        }
                    }
                } else {
                    // 不是离校日就按正常时间，正常日和返校日要接送的也可以出去
                    if (thdId != null && !thdId.equals("")) {
                        pushIds.append(",").append(stuBean.getStudentThdid());
                    }
                }
            }
            if (pushIds.length() > 0)
                pushIds = new StringBuilder(pushIds.substring(1));
            if (notPushIds.length() > 0)
                notPushIds = new StringBuilder(notPushIds.substring(1));
            persons[0] = pushIds.toString();
            persons[1] = notPushIds.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return persons;
    }

    // D.推送某个学生的时间
    public void pushTime(StudentEntity stuBean) {
        ArrangeInformationEntity arrInfo = timingTaskService.attDao.getArrangeInfor(tUtils.getCurrentDate());
        String tableArrange = arrInfo.getArrangeTable();
        String tableCycle = arrInfo.getCycleTable();
        if (tableArrange == null || tableCycle == null || !tableArrange.equals("") || !tableCycle.equals("")) {
            int schoolCode = stuBean.getSchoolCode();
            ArrangeEntity arrBean = timingTaskService.attDao.getDynArrangeBean(tableArrange, stuBean.getGradeId(), schoolCode);
            int dayId = arrBean.getDayId();
            //获得该年级某一种时间段规则
            CycleEntity cycleBean = timingTaskService.attDao.getCycleArrangeList(tableCycle, stuBean.getGradeId(), stuBean.getAllowTime(), schoolCode);
            String deviceIds = getDeviceIds(true, schoolCode, Constants.THDID_AI06);
            SchoolThdidUrlEntity schoolThdidUrl = timingTaskService.schoolDao.getSchoolThdidUrlAndGroupInfo(schoolCode, Constants.THDID_AI06);
            if (schoolThdidUrl != null){
                if (dayId == 4) {
                    new ChangePersonTimeThread(deviceIds, stuBean.getStudentThdid() + "", 0, 1, "rere", 0, 111111111L,
                            99999999999L, "销假重置时间(放假日)", 0, schoolThdidUrl.getPathUrl(), schoolThdidUrl.getAccessToken()).start();
                } else if (dayId == 3) {
                    int stuType = stuBean.getLeaveType();
                    if (1 == stuType) {
                        new ChangePersonTimeThread(deviceIds, stuBean.getStudentThdid() + "", cycleBean.getType(),
                                cycleBean.getCycleId(), cycleBean.getCycleName(),
                                cycleBean.getTimeslot().split(";").length, 111111111L, 99999999999L, "销假重置时间(离校日自行离校)", 0, schoolThdidUrl.getPathUrl(), schoolThdidUrl.getAccessToken())
                                .start();
                    } else {
                        new ChangePersonTimeThread(deviceIds, stuBean.getStudentThdid() + "", 0, 1, "rere", 0, 111111111L,
                                99999999999L, "销假重置时间(离校日非自行离校)", 0, schoolThdidUrl.getPathUrl(), schoolThdidUrl.getAccessToken()).start();
                    }
                } else {
                    new ChangePersonTimeThread(deviceIds, stuBean.getStudentThdid() + "", cycleBean.getType(),
                            cycleBean.getCycleId(), cycleBean.getCycleName(), cycleBean.getTimeslot().split(";").length,
                            111111111L, 99999999999L, "销假重置时间(返校正常日)", 0, schoolThdidUrl.getPathUrl(), schoolThdidUrl.getAccessToken()).start();
                }
            }else {
                logger.error("学校：{}对应的实义德后台：{}不存在", schoolCode, Constants.THDID_AI06);
            }
        } else {
            logger.error("当天的表不存在？？");
        }
    }

    // 2、每天定时create student_record,往record_information里insert
    public void createPassRecord() {
        String todayDate = tUtils.getCurrentDate();
        String tableTail = todayDate.replace("-", "");
        String tableName = "pass_record" + tableTail;
        try {
            timingTaskService.prDao.createPassRecord(tableName);
            int addRes = timingTaskService.prDao.addPassRecordInfor(todayDate, tableName, tUtils.getCurrentDateTime());
            if (!(addRes > 0)) {
                logger.error("addPassRecordInfor失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 3、创建当天的动态时间表
    public void createTableAndPushTime() throws ParseException {
        String curtDate = tUtils.getCurrentDate();
        String tableTail = curtDate.replace("-", "");
        String tableArrange = "dyn_arrange" + tableTail;
        String tableCycle = "dyn_cycle" + tableTail;
        try {
            // 创建当天的动态时间表和当天的时间段规则表，确保有表
            createDynTable(curtDate, tableArrange, tableCycle, null); // 创建人的ID为null
            // 6个年级分开更新当天的时间规则表
            List<ArrangeEntity> dynArrangeBeanList = timingTaskService.attDao.getDynArrangeBeanList(tableArrange);
            for (ArrangeEntity arrBean : dynArrangeBeanList) {
                updateDynCycle(tableCycle, arrBean);
                pushTime(tableCycle, arrBean, arrBean.getCourseId(), arrBean.getSchoolCode());
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    // 4、对请假表里有效的做操作
    public void pushTimeInLeave() {
        Date curDate = new Date();
        List<LeaveRecordEntity> leaveBeanList = timingTaskService.attDao.getValidLeaveListWithoutPushTime();
        for (LeaveRecordEntity leaveBean : leaveBeanList) {
            Date leaveStartTime = leaveBean.getStartTime();
            Date leaveEndTime = leaveBean.getEndTime();
            String studentId = leaveBean.getStudentId();//获取的是学生的ID
            StudentEntity stuBean = timingTaskService.attDao.getStudentBeanById(Integer.parseInt(studentId));
            logger.info("当前执行请假时间信息：=》" + leaveEndTime + "当前时间为：" + curDate);
            if (leaveStartTime.before(curDate) && curDate.before(leaveEndTime)) {
//				if (curDate.before(leaveEndTime)) {
                logger.info("当前执行请假信息推送的学生有：=》" + leaveBean.getLeaveId());
                // 在请假时段里面的要推送时间
                String stuTHDId = stuBean.getStudentThdid() + "";
                Integer schoolCode = stuBean.getSchoolCode();
                MachineEntity machine = new MachineEntity();
                machine.setSchoolCode(schoolCode).setDeviceModel(Constants.THDID_AI06).setIsout(1);
                List<MachineEntity> machineList = timingTaskService.mDao.listMachine(machine);
                for (MachineEntity mBean : machineList) {
                    SchoolThdidUrlEntity schoolThdidUrl = timingTaskService.schoolDao.getSchoolThdidUrlAndGroupInfo(schoolCode, Constants.THDID_AI06);
                    if (schoolThdidUrl != null)
                        new ChangePersonTimeThread(mBean.getMachineId(), stuTHDId, 1, 1, "全天ALL", 100,
                            leaveStartTime.getTime() / 1000, leaveEndTime.getTime() / 1000, "请假任务",
                            leaveBean.getLeaveId(), schoolThdidUrl.getPathUrl(), schoolThdidUrl.getAccessToken()).start();
                }
            } else {
                if (leaveEndTime.before(curDate)) {
                    // 请假结束了还没出校的需要销假
                    Date date = new Date();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    int leaveId = leaveBean.getLeaveId();
                    Boolean updateRes = timingTaskService.attDao.cancelLeaveRecordByLeaveId(leaveId) > 0 ? true : false;
                    PubCountEntity parentopenid = timingTaskService.messageDao.getPubCountOpenidByid(leaveBean.getParentId());
                    PubCountEntity teacheropenid = timingTaskService.messageDao.getPubCountOpenidByid(leaveBean.getTeacherId());
                    String schoolName = schoolDao.getSchoolName(stuBean.getSchoolCode());
                    String[] paramsWeiXin = {"", schoolName, "脸卡通", simpleDateFormat.format(date),
                            "请假申请已过期,请假时间:" + leaveBean.getStartTime() + "-" + leaveBean.getEndTime() + "请假原因:"
                                    + leaveBean.getLeaveContent(),
                            ""};
                    if (parentopenid != null)
                        SendUtils.sendByWeixin(parentopenid, paramsWeiXin,parentopenid.getTemplateId());
                    if (teacheropenid != null)
                        SendUtils.sendByWeixin(teacheropenid, paramsWeiXin,teacheropenid.getTemplateId());
                    if (updateRes) {
                        logger.info(leaveId + "设置过期成功");
                        pushTime(stuBean);
                    }
                } else {
                    // 请假还没开始，不作处理
                }
            }
        }
    }

    // 5更新设备时间
    public void setDeviceTime(Integer schoolCode) {
        List<MachineEntity> mList;
        try {
            MachineEntity machine = new MachineEntity();
            machine.setSchoolCode(schoolCode).setDeviceModel(Constants.THDID_AI06);
            mList = timingTaskService.mDao.listMachine(machine);
            SchoolThdidUrlEntity schoolThdidUrl = timingTaskService.schoolDao.getSchoolThdidUrlAndGroupInfo(schoolCode, Constants.THDID_AI06);
            for (MachineEntity mBean : mList) {
                new SetDeviceTimeThread(mBean.getMachineId(), schoolThdidUrl.getPathUrl(), schoolThdidUrl.getAccessToken()).start();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    // 6,每天查询当天是否是放假日 如果是放假日 则给家长接的学生 推送一条消息 提醒其时间安排，并查看 第二天是否是放假日 如果是则给所有放假学生的家长推送
    // 孩子离校 方式的设置
    public void pushInformationForParent() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        try {
            Date currentDate = new Date(); // 当前时间
            String currentTableName = "dyn_arrange" + simpleDateFormat.format(currentDate);// 当前天的表名
            List<ArrangeEntity> arrBeanList = timingTaskService.attDao.getDynArrangeBeanList(currentTableName);
            for (ArrangeEntity arrangeBean : arrBeanList) {
                if (arrangeBean.getDayId() == 3) {// 说明今天是离校日 需通知家长 接送的时间安排
                    List<StudentEntity> studentBeans = timingTaskService.schoolDao.getPickStudent(arrangeBean.getCourseId());
                    if (studentBeans != null) {
                        for (StudentEntity studentBean : studentBeans) {
                            String phone = timingTaskService.schoolDao.getParentPhoneNum(studentBean.getId());
                            String[] params = {"本周您小孩离校状态为“到校接”，请您安排好接送时间，如果您时间临时有变，建议您在放假前2小时，将小孩离校方式设置为“自行离校”。",
                                    ""};
//							SendUtils.sendByShortMessage(phone, params, "224729");
                            logger.info(studentBean.getStudentName() + "的家长" + currentDate + "收到孩子的接送消息");
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error("定时任务查询放假信息失败~~~~不用管, 失败 说明还没有设置放假时间");
//				getLastDayInfo(simpleDateFormat);
        }
//			getLastDayInfo(simpleDateFormat);
    }

    public static int doNotPushTime(int leaveId) {
        return timingTaskService.attDao.doNotPushTime(leaveId);
    }

    public void checkPayOrder() {
        List<PayOrderEntity> payOrders = timingTaskService.payDao.getPayOrderList();
        Date currentDate = new Date();
        Calendar calendar = new GregorianCalendar();
        for (PayOrderEntity payOrderEntity : payOrders) {
            calendar.setTime(payOrderEntity.getCreateTime());
            calendar.add(Calendar.YEAR, 1);//把日期往后增加一年.整数往后推,负数往前移动
            if (calendar.getTime().before(currentDate)) {//说明已过期则更新 is_out_of_date = 0
                timingTaskService.payDao.updateOrderIsOutOfDate(payOrderEntity.getId());
            }
        }
    }

    public void updatePassRecordSystemId() {
        Calendar now = Calendar.getInstance();
        String passDate = new SimpleDateFormat("yyyyMMdd").format(now.getTime());
        String tableName = "pass_record" + passDate;
        // 前2分钟
        now.add(Calendar.MINUTE, -2);
        String lastTweLveMin = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now.getTime());
        // 查询12分钟前的数据
        List<PassRecordBean> passRecordList = prDao.listPassRecord(tableName, lastTweLveMin);
        for (PassRecordBean passRecord : passRecordList) {
            if (passRecord.getSystemId() != null)
                prDao.updatePassRecord(tableName, passRecord);
        }

    }

    /**
     * 判断第二天 是否是 放假日 如果是 给家长发送一条设置 离校 方式 的 短信
     *
     * xlr 注释 现在 不用了
     *
     * @param simpleDateFormat
     */
//		private void getLastDayInfo(SimpleDateFormat simpleDateFormat) {
//			try {
//				Calendar tmr = Calendar.getInstance(); // 先定义为今天
//				tmr.add(Calendar.DAY_OF_MONTH, 1); // 加上一天，就是明天了
//				String lastTableName = "dyn_arrange" + simpleDateFormat.format(tmr.getTime()); // 第二天的表名
//				List<ArrangeBean> arrBeanList2 = attDao.getDynArrangeBeanList(lastTableName);
//				for (ArrangeBean arrangeBean : arrBeanList2) {
//					System.out.println("555555555555555555555555555++++++++" + arrangeBean.getDay_id());
//					if (arrangeBean.getDay_id() == 3) {// 说明第二天是离校日 需通知家长 去设置孩子的离校方式
//						List<StudentBean> studentBeans = schoolDao.getStudentByGradeID(arrangeBean.getCourse_id());// 根据年级ID查询出所有班级的学生
//						if (studentBeans != null) {
//							for (StudentBean studentBean : studentBeans) {
//								String phone = schoolDao.getParentPhoneNum(studentBean.getId());
//								String[] params = {
//										"本周放假即将到来，为了保证您孩子顺利出校，烦请您对孩子离校方式进行设置。方法是：进入脸卡通智慧校园——点击离校设置——选择方式然后确定即可。","" };
////								SendUtils.sendByShortMessage(phone, params, "224729");
//								System.out.println(
//										"" + studentBean.getCourse_id() + "的家长收到时间为" + simpleDateFormat.format(new Date())
//												+ "$$$$$$$$$$$$$$$$设置$$$$$$$$$$$$$$$消息###" + params[0] + "####");
//							}
//						}
//					}
//				}
//			} catch (SQLException e1) {
//				try {
//					Log.log.error("定时任务查询放假信息失败~~~~不用管, 失败 说明还没有设置放假时间");
//				} catch (Exception e) {
//					// TODO: handle exception
//				}
//				e1.printStackTrace();
//			}
//		}
}

